package 搜索旋转排序数组;

import java.util.Arrays;

public class Solution2 {
    public int search(int[] nums, int target) {

        int low = 0;
        int high = nums.length-1;

        while(low < high){
            int mid = low + (high -low)/2;

            if(nums[mid] == target){
                return mid;
            }

            //如果目标值在左半段
            if(nums[0] <= nums[mid]){
                if(nums[0] <= target && target < nums[mid]){
                    high = mid -1;
                }else{
                    low = mid + 1;
                }
            }else{ //目标值在右边
                if(target > nums[mid] && target <= nums[high]){
                    low = mid +1;
                }else{
                    high = mid -1;
                }
            }
        }

        return -1;
    }
}
